package com.wzy.business.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import com.wzy.business.room.bean.User
import com.wzy.business.room.bean.UserAndLoginInfo


@Dao
interface UserDao {
    @Insert
    fun addUser(vararg store: User): List<Long>

    //更新，若出现冲突，则使用替换策略，还有其他策略可选
    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun updateUser(vararg store: User): Int

    @Delete
    fun deleteUser(vararg store: User): Int

    @Query("SELECT * FROM user where phone like '%'||:phone||'%'")
    fun queryUserByPhone(phone: String): List<User>

    //查询Store与其有关的Master
    @Transaction
    @Query("Select * from user where phone = :phone")
    fun queryUserLoginInfo(phone: String): List<UserAndLoginInfo>

}